package com.class5.springboot.controller;

import com.alibaba.fastjson.JSONObject;
import com.class5.springboot.frame.repo.dto.PageData;
import com.class5.springboot.frame.repo.dto.ParamMap;
import com.class5.springboot.frame.web.SuperRestController;
import com.class5.springboot.frame.web.result.ResultData;
import com.class5.springboot.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class TestController extends SuperRestController {

    @Autowired
    private TestService testService;

    /**
     * @api {POST}  /class5/api/project/findOrgInfoApplyForPage 01.获取企业申报管理列表（分页_监管端），具有分配权限的角色
     * @apiGroup OrgInfoApply
     * @apiDescription  获取企业申报管理列表（分页_监管端），具有分配权限的角色
     * @apiParamExample 参数说明
     * {
     * 	    orgInfoName:企业名称,
     * 	    authorizedName:被授权人姓名,
     *      authorizedPhone:被授权人手机号,
     * 	    submitDate_start：提交时间起,
     * 	    submitDate_end：提交时间止,
     * 	    auditDate_start：审核时间起,
     * 	    auditDate_end：审核时间止,
     *      acceptStatus：分配状态,//1:未分配,2:已分配
     *      auditStatus:审核状态,//1:待提交,2:待审核,3:审核中,4:审核通过,5:审核未通过,6:已取消
     *      projectType:企业类型,//1:生产企业,2:代理企业
     *      auditName:审核人,
     *      page:页码,                        1
     *      size:每页数据条数                 20
     * }
     * @apiSuccessExample 成功后返回
     * {
     *     success:true,
     *     content:[
     *          records:[
     *             {
     * 	    		id:主键ID,
     * 	    		orgInfoName:企业名称,
     * 	    		authorizedName:被授权人姓名,
     * 	    		authorizedPhone:被授权人手机号,
     * 	    		acceptStatus：分配状态('1'未分配||已分配返回分配客服名),
     * 	    	    projectType:企业类型(1:生产企业,2:代理企业),
     * 	    	    submitDate：提交时间,
     * 	    	    auditName:审核人,
     * 	    	    auditStatus:审核状态,
     * 	    	    auditDate:审核时间,
     * 	    	    auditOpinion:审核意见
     * 	    	    }
     *      }
     */
    @PostMapping("/api/project/findOrgInfoApplyForPage")
    public ResultData findOrgInfoApplyForPage(HttpServletRequest request){
        JSONObject param = getBodyObject(request);
        log.info("查询企业申报管理(监管)列表:{}",param.toString());
        PageData pageData = testService.findOrgInfoApplyForPage(ParamMap.get(param));
        return successWraper(pageData);
    }

    @PostMapping("/api/updateTest")
    public ResultData updateTest(HttpServletRequest request){
        JSONObject param = getBodyObject(request);
        log.info("查询企业申报管理(监管)列表:{}",param.toString());
        testService.updateOrgUser(param);
        return successWraper("更新成功");
    }

    @PostMapping("/api/insertTest")
    public ResultData insertTest(HttpServletRequest request){
        JSONObject param = getBodyObject(request);
        log.info("查询企业申报管理(监管)列表:{}",param.toString());
        testService.insertOrgUser(param);
        return successWraper("新增成功");
    }

    @PostMapping("/api/findOrgUserForPage")
    public ResultData findOrgUserForPage(HttpServletRequest request){
        JSONObject param = getBodyObject(request);
        log.info("查询企业申报管理(监管)列表:{}",param.toString());
        PageData pageData = testService.findOrgUserForPage(ParamMap.get(param));
        return successWraper(pageData);
    }

    @PostMapping("/api/findTest")
    public ResultData findTest(HttpServletRequest request){
        JSONObject param = getBodyObject(request);
        log.info("查询企业申报管理(监管)列表:{}",param.toString());
        PageData pageData = testService.findOrgUserForPage(ParamMap.get(param));
        return successWraper("1");
    }

}
